#pragma once

#include <compl.h>
#include <ddblk/adep_dblk.h>

STA_OUFUN(syslock)
lock_t * (* const init) (void *ptr, size_t size);
void * (* const destruct) (lock_t *lock);
bool_t (* const lock) (lock_t *lock);
bool_t (* const unlock) (lock_t *lock);
END_OUFUN(syslock)

#define DECL_SYSLOCK(locktype)			\
SAI _##locktype##lock_t *_##locktype##_init(void *ptr, size_t size);\
SAI void *_##locktype##_destruct(_##locktype##lock_t *s);\
SAI bool_t _##locktype##_lock(_##locktype##lock_t *s);\
SAI bool_t _##locktype##_unlock(_##locktype##lock_t *s);

/* syslock不需要任何依赖 */
#define DEF_SYSLOCK(locktype, name)			\
typedef _##locktype##lock_t name##lock_t;		\
typedef void name##node_t;			\
SAI lock_t *name##_init(void *ptr, size_t size){ return (lock_t *)_##locktype##_init(ptr, size); }\
SAI void *name##_destruct(lock_t *s){ return _##locktype##_destruct((name##lock_t *)s); }\
SAI bool_t name##_slock(lock_t *l){ return _##locktype##_lock((name##lock_t *)l); }\
SAI bool_t name##_sunlock(lock_t *l){ return _##locktype##_unlock((name##lock_t *)l); }\
SAI bool_t name##_lock(lock_t *l, locktoken_t *ptoken){ PARAM_USED(ptoken); return _##locktype##_lock((name##lock_t *)l); }\
SAI bool_t name##_unlock(lock_t *l, locktoken_t token){ PARAM_USED(token); return _##locktype##_unlock((name##lock_t *)l); }\
MAY_UNUSED NEW_OUFUN(syslock, sys_##name, name##_init, name##_destruct, name##_slock, name##_sunlock)\
MAY_UNUSED NEW_OUFUN(lock, name, name##_init, name##_destruct, name##_lock, name##_unlock, name##_lock, name##_unlock)

